package com.itheima.features.optional.demo01;

import java.util.Optional;

public class OptionalDemo03 {

    public static void main(String[] args) {

        Student student = null;//new Student("蓝湛", 15);

        Optional<Student> optional = Optional.ofNullable(student);

//        Student orElse = optional.orElse(new Student("魏婴", 14));
//        System.out.println(orElse);

//        Student orElseGet = optional.orElseGet(() -> {
//            return new Student("魏婴", 14);
//        });

        optional.ifPresent(s -> System.out.println(s + "---当当当"));

        optional.ifPresentOrElse(s -> System.out.println(s + "---叮叮叮"), () -> System.out.println(student + "封装的对象为null"));
    }
}
